package fr.umlv.m2.jee.spij.service.fieldWork;

import fr.umlv.m2.jee.spij.persistence.education.FieldWork;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.Date;

/**
 * DTO that displays datas about {@link FieldWork}.
 *
 * @author thomas magny
 * @author mathieu mazzolini
 */
@Component("fieldWorkBean")
public class DisplayFieldWork implements Serializable {

    /**
     * Primary key.
     */
    private long id;

    /**
     * Closing date for submission. The date is null if no record is expected.
     */
    private Date deadLineDate;

    /**
     * Closing hours for submission.
     */
    private Date deadLineHour;

    /**
     * Instructional date.
     */
    private Date date;

    /**
     * Instructional start time.
     */
    private Date startTime;

    /**
     * Instructional end time.
     */
    private Date endTime;

    /**
     * About teaching.
     */
    private String subject;

    /**
     * Contain of practice.
     */
    private String contain;

    /**
     * Correction of practice.
     */
    private String correction;

    /**
     * Link of practice in PDF.
     */
    private String linkSupport;

    /**
     * Link of correction in PDF.
     */
    private String linkCorrection;

    /**
     * Id of linked unit.
     */
    private long unit;

    /**
     * Name of linked unit.
     */
    private String unitName;

    /**
     * Default constructor.
     */
    public DisplayFieldWork() {
        id = -1l;
        unit = -1l;
    }

    /**
     * Constructors that stores FieldWork datas.
     *
     * @param fieldWork the fieldwork to transfer datas
     */
    public DisplayFieldWork(FieldWork fieldWork) {
        if (fieldWork != null)
            storeData(fieldWork);
    }

    /**
     * Returns the id of the fieldwork.
     * 
     * @return the id of the fieldwork
     */
    public long getId() {
        return id;
    }

    /**
     * Sets the id of the fieldwork with the specified id.
     * 
     * @param id the specified id to set.
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * Returns the deadline's date of the fieldwork.
     * 
     * @return the deadline's date of the fieldwork
     */
    public Date getDeadLineDate() {
        //return new Date(deadLineDate.getTime());
        return deadLineDate;
    }

    /**
     * Sets the deadline's date of the fieldwork with the specified date.
     * 
     * @param deadLineDate the specified deadline's date to set
     */
    public void setDeadLineDate(Date deadLineDate) {
        this.deadLineDate = deadLineDate;
    }

    /**
     * Returns the deadline's hour of the fieldwork.
     * 
     * @return the deadline's hour of the fieldwork
     */
    public Date getDeadLineHour() {
        //return new Date(deadLineHour.getTime());
        return deadLineHour;
    }

    /**
     * Sets the deadline's hour of the fieldwork with the specified hour.
     * 
     * @param deadLineHour the specified deadline's hour to set
     */
    public void setDeadLineHour(Date deadLineHour) {
        this.deadLineHour = deadLineHour;
    }

    /**
     * Returns the instructional date of the fieldwork.
     * 
     * @return the instructional date of the fieldwork
     */
    public Date getDate() {
        return new Date(date.getTime());
    }

    /**
     * Sets the instructional date of the fieldwork with the specified date.
     * 
     * @param date the specified instructional date to set
     */
    public void setDate(Date date) {
        this.date = new Date(date.getTime());
    }

    /**
     * Returns the instructional start time of the fieldwork.
     * 
     * @return the instructional start time of the fieldwork
     */
    public Date getStartTime() {
        return new Date(startTime.getTime());
    }

    /**
     * Sets the instructional start time of the fieldwork with the specified
     * hour.
     * 
     * @param startTime the specified instructional start time to set
     */
    public void setStartTime(Date startTime) {
        this.startTime = new Date(startTime.getTime());
    }

    /**
     * Returns the instructional end time of the fieldwork.
     * 
     * @returnthe instructional end time of the fieldwork
     */
    public Date getEndTime() {
        return new Date(endTime.getTime());
    }

    /**
     * Sets the instructional end time of the fieldwork with the specified
     * hour.
     * 
     * @param endTime the specified instructional end time to set
     */
    public void setEndTime(Date endTime) {
        this.endTime = new Date(endTime.getTime());
    }

    /**
     * Returns the subject of the fieldwork.
     * 
     * @return the subject of the fieldwork
     */
    public String getSubject() {
        return subject;
    }

    /**
     * Sets the subject of the fieldwork with the specified string.
     * 
     * @param subject the subject to set
     */
    public void setSubject(String subject) {
        this.subject = subject;
    }

    /**
     * Returns the contain of the fieldwork.
     * 
     * @return the contain of the fieldwork
     */
    public String getContain() {
        return contain;
    }

    /**
     * Sets the contain of the fieldwork with the specified string.
     * 
     * @param contain the contain to set
     */
    public void setContain(String contain) {
        this.contain = contain;
    }

    /**
     * Returns the correction of the fieldwork.
     * 
     * @return the correction of the fieldwork
     */
    public String getCorrection() {
        return correction;
    }

    /**
     * Sets the correction of the fieldwork with the specified string.
     * 
     * @param correction the correction to set
     */
    public void setCorrection(String correction) {
        this.correction = correction;
    }

    /**
     * Returns the support's link of the fieldwork.
     * 
     * @return the support's link of the fieldwork
     */
    public String getLinkSupport() {
        return linkSupport;
    }

    /**
     * Sets the support's link of the fieldwork with the specified string.
     * 
     * @param linkSupport the support's link to set
     */
    public void setLinkSupport(String linkSupport) {
        this.linkSupport = linkSupport;
    }

    /**
     * Returns the correction's link of the fieldwork.
     * 
     * @return the correction's link of the fieldwork
     */
    public String getLinkCorrection() {
        return linkCorrection;
    }

    /**
     * Sets the correction's link of the fieldwork with the specified string.
     * 
     * @param linkCorrection the correction's link to set
     */
    public void setLinkCorrection(String linkCorrection) {
        this.linkCorrection = linkCorrection;
    }

    /**
     * Returns the unit's id of the fieldwork.
     * 
     * @return the unit's id of the fieldwork
     */
    public long getUnit() {
        return unit;
    }

    /**
     * Sets the unit's id of the fieldwork with the specified long.
     * 
     * @param unit the unit's id to set
     */
    public void setUnit(long unit) {
        this.unit = unit;
    }

    /**
     * Returns the unit's name of the fieldwork.
     * 
     * @return the unit's name of the fieldwork
     */
    public String getUnitName() {
        return unitName;
    }

    /**
     * Sets the unit's name of the fieldwork with the specified string.
     * 
     * @param unitName the unit's name to set
     */
    public void setUnitName(String unitName) {
        this.unitName = unitName;
    }

    /**
     * Stores fieldwork's data to this DTO.
     * @param fieldWork the fieldwork with data to store
     */
    private void storeData(FieldWork fieldWork) {
        if (fieldWork.getId() > 0)
            setId(fieldWork.getId());
        if (fieldWork.getUnit() != null && fieldWork.getUnit() > 0) {
            setUnit(fieldWork.getUnit());
        }
        if (!fieldWork.getContain().isEmpty())
            setContain(fieldWork.getContain());
        if (!fieldWork.getCorrection().isEmpty())
            setCorrection(fieldWork.getCorrection());
        if (fieldWork.getDuration() != null) {
            setDate(fieldWork.getDuration().getStart().toDate());
            setStartTime(fieldWork.getDuration().getStart().toDate());
            setEndTime(fieldWork.getDuration().getEnd().toDate());
        }
        if (fieldWork.getDeadLine() != null) {
            setDeadLineDate(fieldWork.getDeadLine().toDate());
            setDeadLineHour(fieldWork.getDeadLine().toDate());
        }
        if (!fieldWork.getLinkCorrection().isEmpty())
            setLinkCorrection(fieldWork.getLinkCorrection());
        if (!fieldWork.getLinkSupport().isEmpty())
            setLinkSupport(fieldWork.getLinkSupport());
        if (!fieldWork.getSubject().isEmpty())
            setSubject(fieldWork.getSubject());
    }
}
